#include<iostream>
using namespace std;
typedef pair<int, int>PII;
const int N = 1e5 + 10;
int arr[N];
int n;
int fun(int l, int r ,int &s ,int &e)
{
	if (l == r) {
		s = l;
		e = r;
		return arr[l];
	}
	int mid = (l + r) >> 1;
	int sum1 = fun(l, mid, s, e);
	int sum2 = fun(mid + 1, r, s, e);
	int ls = 0, lmax = 0;
	int rs = 0, rmax = 0;
	for (int i = mid; i >= l; i--) {
		ls += arr[i];
		//lmax = max(lmax, ls);
		if (ls > lmax) {
			lmax = ls;
			s = i;
		}
	}
	for (int i = mid + 1; i <= r; i++) {
		rs += arr[i];
		//rmax = max(rmax, rs);
		if (rs > rmax) {
			rmax = rs;
			e = i;
		}
	}
	int sum3 = lmax + rmax;
	return max(sum3, max(sum1, sum2));
}
int main()
{
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> arr[i];
	}
	int start = 0, end = 0;
	int ans = fun(0, n - 1 ,start , end);
	cout << ans << endl;
	cout << start << " " << end << endl;
	return 0;	
}